package cn.linstudy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    /*@Autowired
    RestTemplate restTemplate;

    @Autowired
    OrderService orderService;
    @RequestMapping("getById")
    public Order getById(Long oid,Long pid){
        *//*Product product = restTemplate.getForObject(
                "http://localhost:8081/product?pid="+pid,Product.class); // 这里通过restTemplate去发起http请求，请求地址是http://localhost:8083/product，携带的参数是productId
        Order order = orderService.getById(oid, product.getPid());
        order.setUsername(product.getPname());
        return order;*//*
        Product product = restTemplate
                .getForObject("http://product-service/product?pid=" + pid, Product.class);
        Order order = orderService.getById(oid,pid);
        order.setPname(product.getPname());
        return order;
    }*/

    @Autowired
    ProductFeignApi productFeignApi;
    @Autowired
    OrderService orderService;

    @RequestMapping("getById")
    public Order getById(Long oid, Long pid) {
        Product product = productFeignApi.findById(pid);
        Order order = orderService.getById(oid,pid);
        order.setPname(product.getPname());
        return order;
    }





}
